package com.ruoyi.web.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.web.domain.SoftwareLink;
import com.ruoyi.web.service.ISoftwareLinkService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 下载链接Controller
 * 
 * @author song
 * @date 2024-08-26
 */
@RestController
@RequestMapping("/software/link")
public class SoftwareLinkController extends BaseController
{
    @Autowired
    private ISoftwareLinkService softwareLinkService;

    /**
     * 查询下载链接列表
     */
    @PreAuthorize("@ss.hasPermi('software:link:list')")
    @GetMapping("/list")
    public TableDataInfo list(SoftwareLink softwareLink)
    {
        startPage();
        List<SoftwareLink> list = softwareLinkService.selectSoftwareLinkList(softwareLink);
        return getDataTable(list);
    }

    /**
     * 导出下载链接列表
     */
    @PreAuthorize("@ss.hasPermi('software:link:export')")
    @Log(title = "下载链接", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SoftwareLink softwareLink)
    {
        List<SoftwareLink> list = softwareLinkService.selectSoftwareLinkList(softwareLink);
        ExcelUtil<SoftwareLink> util = new ExcelUtil<SoftwareLink>(SoftwareLink.class);
        util.exportExcel(response, list, "下载链接数据");
    }

    /**
     * 获取下载链接详细信息
     */
    @PreAuthorize("@ss.hasPermi('software:link:query')")
    @GetMapping(value = "/{linkId}")
    public AjaxResult getInfo(@PathVariable("linkId") Long linkId)
    {
        return success(softwareLinkService.selectSoftwareLinkByLinkId(linkId));
    }

    /**
     * 新增下载链接
     */
    @PreAuthorize("@ss.hasPermi('software:link:add')")
    @Log(title = "下载链接", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SoftwareLink softwareLink)
    {
        return toAjax(softwareLinkService.insertSoftwareLink(softwareLink));
    }

    /**
     * 修改下载链接
     */
    @PreAuthorize("@ss.hasPermi('software:link:edit')")
    @Log(title = "下载链接", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SoftwareLink softwareLink)
    {
        return toAjax(softwareLinkService.updateSoftwareLink(softwareLink));
    }

    /**
     * 删除下载链接
     */
    @PreAuthorize("@ss.hasPermi('software:link:remove')")
    @Log(title = "下载链接", businessType = BusinessType.DELETE)
	@DeleteMapping("/{linkIds}")
    public AjaxResult remove(@PathVariable Long[] linkIds)
    {
        return toAjax(softwareLinkService.deleteSoftwareLinkByLinkIds(linkIds));
    }
}
